﻿using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using VIT.DataHelper.DataAccess;

namespace VIT.Business
{
    public class Logo : Logo_Base
    {
        SQLSupport sqlSupport = new SQLSupport();

        #region Constructor
        public Logo(string Id = "",
                        string PositionId = "",
                        string LanguageId = "",
                        string Link = "",
                        string FileName = "",
                        string FullLogo = "",
                        string Title = "",
                        string Description = "")
        {
            this.Id = Id;
            this.PositionId = PositionId;
            this.LanguageId = LanguageId;
            this.Link = Link;
            this.FileName = FileName;
            this.FullLogo = FullLogo;
            this.Title = Title;
            this.Description = Description;
        }
        #endregion

        #region Pre
        public DataTable GetList(string position)
        {
            string strQuery = "select Id, Link, FileName, FullLogo, Title, Description from Logo, Logo_Language where Id=LogoId and LanguageID=@LanguageID and PositionId=@PositionId and Published=1 order by Orders";
            SqlParameter LanguageId = new SqlParameter("@LanguageID", this.LanguageId);
            SqlParameter Position = new SqlParameter("@PositionId", position);
            return sqlSupport.ExecuteDataset(false, strQuery, LanguageId, Position).Tables[0];
        }

        public void GetOne()
        {            
            string strQuery = "select Id, PositionId, Link, FileName, FullLogo, Title, Description from Logo, Logo_Language where LanguageID=@LanguageId and Id=@Id and Published=1";
            SqlParameter Id = new SqlParameter("@Id", this.Id);
            SqlParameter LanguageId = new SqlParameter("@LanguageId", this.LanguageId);
            DataTable dt = sqlSupport.ExecuteDataset(false, strQuery, Id, LanguageId).Tables[0];

            if (dt.Rows.Count > 0)
            {
                this.PositionId = dt.Rows[0]["PositionId"].ToString();
                this.Link = dt.Rows[0]["Link"].ToString();
                this.FileName = dt.Rows[0]["FileName"].ToString();
                this.FullLogo = dt.Rows[0]["FullLogo"].ToString();
                this.Title = dt.Rows[0]["Title"].ToString();
                this.Description = dt.Rows[0]["Description"].ToString();                
            }
            else this.Id = "";
        }
        #endregion
    }
}
